Ext.define('DragonApp.store.JsonPMonster', {
    extend: 'Ext.data.Store',

    model: 'DragonApp.model.Monster',

    alias: 'store.jsonPmonsterStore',

    proxy: {
        url: DragonApp.ux.config.Config.getUrl('/index/Monster/queryBasicInfo/'),
        type: 'jsonp',
        callbackKey: 'callback',
        reader: {
            type: 'json',
            rootProperty: 'rows',
            totalProperty: 'total'
        }
    },
    autoLoad: false,
    listeners: {

        exception: function(proxy, response, operation) {
            DragonApp.util.Msg.showErrorMsg(response);
        }
        /*
        load: {
          fn: function ( me , records , successful , operation , eOpts ) {

            if (successful == true) {

              var ori_records = records;

              var _arr = [
                {'store':Ext.create('DragonApp.store.MonsterLocation'),'field_s':'location','field_m':'id','field_v':'name'},
                {'store':Ext.create('DragonApp.store.Quality'), 'field_s':'quality','field_m':'id','field_v':'name'}];

              for(var i= 0;i<_arr.length;i++){

                var matchStore = _arr[i]['store'];
                var sourceField = _arr[i]['field_s'];
                var matchField = _arr[i]['field_m'];
                var valueField = _arr[i]['field_v'];

                !function(matchStore,sourceField,matchField,valueField){

                  //============
                  //遍历数组加载,
                  //匹配仓库
                  //============
                  matchStore.load({
                    callback: function(records, operation, success) {
                      if (false === success) {
                        return false;
                      } else if (true === success) {

                        for (var _i = 0; _i < ori_records.length; _i++) { //遍历源始仓库

                          var hasMatch = false;
                          var finalValue = null;
                          var record = ori_records[_i];

                          for (var _j = 0; _j < records.length; _j++) { //遍历匹配仓库
                            var matchRecord = records[_j];

                            //寻找匹配记录
                            if (record.get(sourceField) == matchRecord.get(matchField)) {
                              finalValue = matchRecord.get(valueField);
                              hasMatch = true;
                              break;
                            }
                          }
                          if(true===hasMatch){
                            record.set(sourceField, finalValue);  //匹配字段赋值
                          }
                        }
                        me.commitChanges();
                      }
                    }
                  });
                }(matchStore,sourceField,matchField,valueField);
              }
            }
          }
        }*/
    }
});